﻿@using Smartstore.Web.Rendering.Menus
@using Smartstore.Collections
@using Smartstore.Core.Content.Menus

@model MenuModel

@{
    var root = Model.Root;
    if (root == null)
    {
        return;
    }
}

@functions {
    public string GetNodeLink(TreeNode<MenuItem> node)
    {
        if (node.HasChildren)
        {
            return "javascript:void(0)";
        }

        return node.Value.GenerateUrl(this.ViewContext);
    }
}

<div class="menu-settings tabbable tabs-stacked tabs-left ml-2 my-2 d-block">
    <nav class="nav-aside">
        <ul class="nav nav-tabs nav-tabs-line flex-column nav-stacked nav-left" data-menu-name="settings">
            @{
                var isCurrent = false;
                foreach (var node in Model.Root.Children)
                {
                    var item = node.Value;
                    var isSelected = false;

                    if (!item.Visible)
                    {
                        continue;
                    }

                    if (!isCurrent)
                    {
                        // No need to check further if selected node is found once.
                        isCurrent = item.IsCurrent(ViewContext);
                        isSelected = isCurrent;
                    }

                    var itemText = node.GetItemText(T);
                    var itemUrl = GetNodeLink(node);
                    var icon = item.Icon.NullEmpty() ?? "fas fa-fw";

                    <li class="nav-item">
                        <a class="nav-link text-left" attr-class='(isSelected, "active")' href="@itemUrl">
                            @if (item.IconLibrary == "bi")
                            {
                                <bootstrap-icon name="@icon" class="nav-icon" attr-class='@(item.IconClass.HasValue(), item.IconClass)' />
                            }
                            else
                            {
                                <i class="nav-icon @icon" attr-class='@(item.IconClass.HasValue(), item.IconClass)'></i>
                            }
                            <span class="tab-caption">@itemText</span>
                        </a>
                    </li>
                }
            }
        </ul>
    </nav>
</div>